<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>教师登录</title>
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <script src="../js/jquery-3.6.0.js"></script>
</head>

<body>

<img class="bgone" src="img/1.jpg" />
<img class="pic" src="img/a.png" />

<div class="table">
    <div class="wel">工程教育认证系统</div>
    <div class="wel1">GONG CHENG JIAO YU REN ZHENG XI TONG</div>

    <!-- 身份切换按钮 -->
    <div class="identity-switch">
        <span class="identity-text" id="studentLink">学生</span>
        <span class="identity-divider">|</span>
        <span class="identity-text active">教师</span>
    </div>

    <div class="user">
        <div style=""><img src="img/yhm.png" /></div>
        <input type="text" name="" placeholder="用户名" id="username"/>
    </div>
    <div class="password">
        <div><img src="img/mm.png" /></div>
        <input type="password" name="密码" placeholder="●●●●●●" id="password"/>
    </div>
    <input class="btn" type="button" name="登录" value="登录" id="loginButton"/>
</div>

</body>
<script>
    $(document).ready(function() {
        // 身份切换功能
        $("#studentLink").click(function() {
            window.location.href = "StuLogin.html";
        });

        $("#loginButton").click(function () {
            let username = $("#username").val();
            let password = $("#password").val();

            if(username == null || username.trim() === ""){
                alert("请输入用户名");
                return;
            }

            if(password == null || password.trim() === ""){
                alert("请输入密码");
                return;
            }

            $.ajax({
                url:"/teacherUser/login",
                type:"post",
                cache:false,
                contentType:"application/json;charset=utf-8",
                data: JSON.stringify({
                    username:username,
                    password:password
                }),
                dataType:"json",
                success:function(response){
                    console.log("返回: " + JSON.stringify(response));
                    if(response.code === 200) {
                        alert("登录成功, 欢迎您！ " + username);
                        window.location.href ="../Teacher.html";

                    }
                    else {
                        alert(response.msg);
                    }
                },
                error:function(response){
                    console.log("出错返回: " + JSON.stringify(response));
                    alert("登录请求失败，请检查网络连接或联系管理员");
                }
            });
        });
    });
</script>
</html>
